package com.mths.server.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Entity
@SQLDelete(sql = "update COMPANY_DOCUMENT_META set status='P' where objid=?")
@Where(clause = "status='A'")
@Table(name = "COMPANY_DOCUMENT_META")
public class CompanyDocumentMeta extends AbstractEntity {

	@Where(clause = "status='A'")
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "COMPANY_DOCUMENT_OID", nullable = false)
	private CompanyDocument companyDocument;

	@Where(clause = "status='A'")
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "META_DATA_OID", nullable = false)
	private MetaData metaData;

	@Column(name = "META_VALUE", length = 50)
	private String metaValue;

	public CompanyDocument getCompanyDocument() {
		return companyDocument;
	}

	public void setCompanyDocument(CompanyDocument companyDocument) {
		this.companyDocument = companyDocument;
	}

	public MetaData getMetaData() {
		return metaData;
	}

	public void setMetaData(MetaData metaData) {
		this.metaData = metaData;
	}

	public String getMetaValue() {
		return metaValue;
	}

	public void setMetaValue(String metaValue) {
		this.metaValue = metaValue;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((companyDocument == null) ? 0 : companyDocument.hashCode());
		result = prime * result + ((metaData == null) ? 0 : metaData.hashCode());
		result = prime * result + ((metaValue == null) ? 0 : metaValue.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		CompanyDocumentMeta other = (CompanyDocumentMeta) obj;
		if (companyDocument == null) {
			if (other.companyDocument != null)
				return false;
		} else if (!companyDocument.equals(other.companyDocument))
			return false;
		if (metaData == null) {
			if (other.metaData != null)
				return false;
		} else if (!metaData.equals(other.metaData))
			return false;
		if (metaValue == null) {
			if (other.metaValue != null)
				return false;
		} else if (!metaValue.equals(other.metaValue))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "CompanyDocumentMeta [companyDocument=" + companyDocument + ", metaData=" + metaData + ", metaValue=" + metaValue + "]";
	}

}